FROM golang:1.19 as builder

ARG TARGETOS
ARG TARGETARCH

WORKDIR /workspace

COPY go.mod go.mod
COPY go.sum go.sum

ENV GOPROXY https://proxy.golang.com.cn,direct
RUN go mod download

COPY main.go main.go
COPY collectors/ collectors/
COPY common/ common/

RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o dnsexpiry main.go


FROM gcr.io/distroless/static:nonroot
WORKDIR /
COPY --from=builder /workspace/dnsexpiry .
USER 65532:65532

EXPOSE 9999

ENTRYPOINT [ "/dnsexpiry" ]